import React from 'react';
import {Checkbox} from 'antd';
const CheckboxGroup = Checkbox.Group;
import {WeaSearchGroup, WeaFormItem} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import EType from './base/EType';
import ETitle from './base/ETitle';
import ELinkMode from './base/ELinkMode';
//import EField from './base/EField';
import EField_New from './base/EField_New'

// 期刊中心
export default class Content_18 extends React.Component {
    state = {
        eMagazine: this.props.eMagazine.checked,
        eFieldNewDataSource: this.props.eFieldNewDataSource,
        eFieldNewUsedKeys: this.props.eFieldNewUsedKeys,
        eFieldNewVisible: false,
    };

    render() {
        const { eMagazine, eFieldNewDataSource, eFieldNewUsedKeys, eFieldNewVisible } = this.state;

        let EMagazine = <div></div>;
        if (this.props.eShareLevel == '2') {
            EMagazine = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@o4hmie`} label={getLabel(20052, '期刊列表')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <div className="portal-esetting-checkbox-group">
                        <CheckboxGroup ecId={`${this && this.props && this.props.ecId || ''}_CheckboxGroup@n6wg9x`} size="default" options={this.props.eMagazine.options} value={eMagazine} onChange={checkedValue => this.setState({eMagazine: checkedValue})}/>
                    </div>
                </WeaFormItem>
            );
        }

        let EFieldNewshow = <div></div>;
        let EFieldNew = <div></div>;
        if (eFieldNewVisible) {
            const eFieldNewProps = {
                eFieldNewDataSource: _.cloneDeep(eFieldNewDataSource),
                eFieldNewUsedKeys: _.cloneDeep(eFieldNewUsedKeys),
                onOk: (data) => {
                    this.setState({
                        eFieldNewDataSource: _.cloneDeep(data.eFieldNewDataSource),
                        eFieldNewUsedKeys: _.cloneDeep(data.eFieldNewUsedKeys),
                        eFieldNewVisible: false
                    });
                },
                onCancel: () => {
                    this.setState({
                        eFieldNewVisible: false
                    });
                }
            };
            EFieldNewshow = (
                <EField_New ecId={`${this && this.props && this.props.ecId || ''}_EField_New@i6has2`} {...eFieldNewProps}/>
            );
        }
        const eFieldNewUsedNames = [];
        for (let i = 0; i < eFieldNewUsedKeys.length; i++) {
            for (let j = 0 ; j < eFieldNewDataSource.length; j++) {
                if (eFieldNewUsedKeys[i] == eFieldNewDataSource[j].key) {
                    eFieldNewUsedNames.push(eFieldNewDataSource[j].name);
                }
            }
        }
        
        EFieldNew = this.props.eShareLevel == '2' ? (
            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@c9ahkc`} label={getLabel(19495, '显示字段')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                {EFieldNewshow}
                <div style={{height: '30px', lineHeight: '23px'}}>
                    <i className="icon-coms-Flow-setting portal-esetting-btn" onClick={() => this.setState({eFieldNewVisible: true})}/>
                    <span>{eFieldNewUsedNames.join('，')}</span>
                </div>
            </WeaFormItem>
        ) : '';

        return (
            <div>
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@lzlag7`} title={getLabel(81711, '基本信息')} needTigger={true} showGroup={true}>
                    <EType ecId={`${this && this.props && this.props.ecId || ''}_EType@h7cab1`} ref="eType" value={this.props.eBaseName}/>
                    {this.props.eShareLevel == '2' ? <ETitle ecId={`${this && this.props && this.props.ecId || ''}_ETitle@kie49k`} ref="eTitle" eid={this.props.eid} value={this.props.eTitle} {...this.props}/> : ''}
                    <ELinkMode ecId={`${this && this.props && this.props.ecId || ''}_ELinkMode@pm691d`} ref="eLinkMode" options={this.props.eLinkMode.options} value={this.props.eLinkMode.selected}/>
                    {/*<EField ref="eField" value={this.props.eField}/>*/}
                    {EFieldNew}
                    {EMagazine}
                </WeaSearchGroup>
            </div>
        );
    }

    getSaveValues() {
        return {
            eContentTitle: this.refs['eTitle'] ? this.refs['eTitle'].getSaveValues() : this.props.eTitle,
            eContentLinkMode: this.refs['eLinkMode'].getSaveValues(),
            eContentFieldNewUsedKeys: this.state.eFieldNewUsedKeys,
            eContentMagazine: this.state.eMagazine
        };
    }
}